package week05;

import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

class PersonSortable1{
	private String name;
	private int age;
	
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name 

 = name;
	}
	public int getAge() {
		return age;
	}
	public void setAge(int age) {
		this.age = age;
	}
	public PersonSortable1(String name, int age) {
		this.name 

 = name;
		this.age = age;
	}
	public String toString() {
		return name + "-" + age;
	}
}
class NameComparator implements Comparator<PersonSortable1>{

	public int compare(PersonSortable1 o1, PersonSortable1 o2) {
		// TODO Auto-generated method stub
		return o1.getName().compareTo(o2.getName());
	}
	
}
class AgeComparator implements Comparator<PersonSortable1>{

	@Override
	public int compare(PersonSortable1 o1, PersonSortable1 o2) {
		int n=0;
		if(o1.getAge()>o2.getAge())
			n=1;
		else if(o1.getAge()==o2.getAge())
			n=0;
		else if(o1.getAge()<o2.getAge())
			n=-1;
		return n;
	}
	
}

public class Pta2{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in 

);
		int n=sc.nextInt();
		PersonSortable1[] person=new PersonSortable1[n];
		for(int i=0;i<n;i++){
			person[i]=new PersonSortable1(sc.next(),sc.nextInt());
		}
		System.out.println("NameComparator:sort");
		Arrays.sort(person,new NameComparator());
		for(int i=0;i<n;i++){
			System.out.println(person[i]);
		}
		System.out.println("AgeComparator:sort");
		Arrays.sort(person,new AgeComparator());
		for(int i=0;i<n;i++){
			System.out.println(person[i]);
		}
		System.out.println(Arrays.toString(NameComparator.class.getInterfaces()));
		System.out.println(Arrays.toString(AgeComparator.class.getInterfaces()));
	}
}
